package MaintMenu.SyncInventoryToCat;

import javax.swing.*;
import java.sql.*;

public class UpdCapa
{
    String tbl="";
    String pl="";
    String charc="";
    char lastC;
    String charc1="";
    char lastC1;
    int totalfiles=1;
    String isCapa="";
    boolean capa;
    String oPL="";
    int pkg=0;
    Double cuft=0.00D;
    int rowupd=0;
    public UpdCapa(){
        int x=0;
        int y=0;
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String dataSourceName = "dbLI";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection conli = DriverManager.getConnection(dbURL, "", "");
            Statement stli = conli.createStatement();
            Statement stli1= conli.createStatement();

            String[] sql= new String[7];
            sql[0]="update tblinventory set capa=false";
            sql[1]="update tblbcn set capa=false";
            sql[2]="update tblhfn set capa=false";
            sql[3]="update tblcln set capa=false";
            sql[4]="update tblmrn set capa=false";
            sql[5]="update tblotn set capa=false";
            sql[6]="update tblltn set capa=false";

//                            System.out.println(sql);
            for (int k=0;k<sql.length;k++){
//                System.out.println(k);

//                System.out.println(sql[k]);
                stli1.executeUpdate(sql[k]);
//                System.out.println(sql.length);
            }
            stli.execute("select * from tblinventory");

            ResultSet resultSet1 = stli.getResultSet();
            if (resultSet1 != null)  {
                while (resultSet1.next()) {
                        pl= resultSet1.getString("part#");
                        charc=pl.substring(pl.length() - 1);
                        lastC=charc.charAt(0);
                        charc1=pl.length() > 2 ? pl.substring(pl.length() - 2) : pl;
//                        charc1=charc1.toString();
                        if (lastC=='Q'){
//                            String[] sqlcapa= new String[7];
                            sql[0]="update tblinventory set capa=true where [part#]='"+pl+"'";
                            sql[1]="update tblbcn  set capa=true where [part#]='"+pl+"'";
                            sql[2]="update tblhfn  set capa=true where [part#]='"+pl+"'";
                            sql[3]="update tblcln  set capa=true where [part#]='"+pl+"'";
                            sql[4]="update tblmrn  set capa=true where [part#]='"+pl+"'";
                            sql[5]="update tblotn  set capa=true where [part#]='"+pl+"'";
                            sql[6]="update tblltn  set capa=true where [part#]='"+pl+"'";
//                            System.out.println(sql);
                            for (int k=0;k<sql.length;k++){
//                                System.out.println(sql[k]);
                                rowupd=stli1.executeUpdate(sql[k]);
//                                System.out.print("|========              |\r");
//                                System.out.print("|======================|\r");
                            }
                        }else  if (charc1.equals("QQ")){
//                            String[] sqlcapa= new String[7];
                            sql[0]="update tblinventory set capa=false where [part#]='"+pl+"'";
                            sql[1]="update tblbcn  set capa=false where [part#]='"+pl+"'";
                            sql[2]="update tblhfn  set capa=false where [part#]='"+pl+"'";
                            sql[3]="update tblcln  set capa=false where [part#]='"+pl+"'";
                            sql[4]="update tblmrn  set capa=false where [part#]='"+pl+"'";
                            sql[5]="update tblotn  set capa=false where [part#]='"+pl+"'";
                            sql[6]="update tblltn  set capa=false where [part#]='"+pl+"'";
//                            System.out.println(sql);
                            for (int k=0;k<sql.length;k++){
                                stli1.executeUpdate(sql[k]);
//                                System.out.print(">");
                            }
                        }
                }
            }
            stli.close();
            stli1.close();
            conli.close();}
        catch(Exception e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(null,e);}
    }
}
